This project was created as part of the Developing Data Products course of the Coursera Data Science Specialisation. The goal of the project is to create a web page using R Markdown wth a map created with Leaflet, and to host the resulting web page.
OurAirports is a free site where visitors can explore the world’s airports, read other people’s comments, and leave their own. For current example we use a CSV-formatted data dump of all our airports, countries, and regions, which is updated every night.
Structure of airports data:
## 'data.frame': 52775 obs. of 18 variables:
## $ id : int 6523 323361 6524 6525 6526 322127 6527 6528 324424 322658 ...
## $ ident : chr "00A" "00AA" "00AK" "00AL" ...
## $ type : chr "heliport" "small_airport" "small_airport" "small_airport" ...
## $ name : chr "Total Rf Heliport" "Aero B Ranch Airport" "Lowell Field" "Epps Airpark" ...
## $ latitude_deg : chr "40.07080078125" "38.704022" "59.94919968" "34.86479949951172" ...
## $ longitude_deg : chr "-74.93360137939453" "-101.473911" "-151.695999146" "-86.77030181884766" ...
## $ elevation_ft : int 11 3435 450 820 237 1100 3810 3038 87 3350 ...
## $ continent : chr NA NA NA NA ...
## $ iso_country : chr "US" "US" "US" "US" ...
## $ iso_region : chr "US-PA" "US-KS" "US-AK" "US-AL" ...
## $ municipality : chr "Bensalem" "Leoti" "Anchor Point" "Harvest" ...
## $ scheduled_service: chr "no" "no" "no" "no" ...
## $ gps_code : chr "00A" "00AA" "00AK" "00AL" ...
## $ iata_code : chr "" "" "" "" ...
## $ local_code : chr "00A" "00AA" "00AK" "00AL" ...
## $ home_link : chr "" "" "" "" ...
## $ wikipedia_link : chr "" "" "" "" ...
## $ keywords : chr "" "" "" "" ...
Build custom icons:
planeIcons <- icons(
iconUrl = ifelse(airports$type == "heliport", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/helicopter-airport.png",
ifelse(airports$type == "small_airport", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/small-airport.png",
ifelse(airports$type == "closed", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/closed-airport.png",
ifelse(airports$type == "seaplane_base", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/sea-plane-airport.png",
ifelse(airports$type == "balloonport", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/ballon-airport.png",
ifelse(airports$type == "medium_airport", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/medium-airport.png",
ifelse(airports$type == "large_airport", "https://iaroslav-iefimenko.github.io/RandLeaflet/icons/large-airport.png",
"https://iaroslav-iefimenko.github.io/RandLeaflet/icons/unknown-airport.png"))))))),
iconWidth = 16, iconHeight = 16,
iconAnchorX = 16, iconAnchorY = 16
)
Build and show map:
map <- leaflet(data = airports) %>% addTiles() %>%
addMarkers(lng = ~longitude_deg, lat = ~latitude_deg, label = ~name,
clusterOptions = markerClusterOptions(), icon = planeIcons,
popup = ~paste(sep = "<br/>",
"<b>Airport name:</b>", name, "<b>Airport type:</b>", type, "<b>ISO Country:</b>", iso_country,
"<b>Ident:</b>", ident, "<b>Home link:</b>", home_link, "<b>Wikipedia link:</b>", wikipedia_link
))
map